package leetcode.code;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution495 implements IDebug {
	public int findPoisonedDuration(int[] timeSeries, int duration) {
		int len = timeSeries.length;
		int ans = 0;
		int start = 0;
		for (int end = 1; end < len; end++) {
			if (timeSeries[end - 1] + duration < timeSeries[end]) {
				ans += timeSeries[end - 1] + duration - timeSeries[start];
				start = end;
			}
		}
		ans += timeSeries[len - 1] + duration - timeSeries[start];
		return ans;
	}

	@Override
	public void debug1() {
		int r = this.findPoisonedDuration(HelpDebug.str2array3("[1,4]"), 2);
		int e = 4;
		HelpDebug.compare(e, r);

	}

	@Override
	public void debug2() {
		int r = this.findPoisonedDuration(HelpDebug.str2array3("[1]"), 2);
		int e = 2;
		HelpDebug.compare(e, r);

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution495 so = new Solution495();
		so.debug1();
		so.debug2();

	}

}
